﻿using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System.ComponentModel.Composition.Hosting;
using WooCoo.Data;
using WooCoo;
using WooCoo.DataPortal;
using WooCoo.ObjectModel;

namespace WooCooTest.DataPortal
{
    [TestClass]
    public class PortalRequest
    {
        [TestMethod]
        public void TestIOC()
        {
            var catalog = new DirectoryCatalog(System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory));
            var container = new CompositionContainer(catalog);
            var uop = container.GetExportedValue<IUserOp>();
            //container.GetExport
            //container.
            //container.GetExportedValues();
            //var uop = WooCoo.IoC.Container.Export<IUserOp>();
            //container.get.ComposeParts(this, new BookService());
            //uop.ShowName("");

        }
        [TestMethod]
        public void TestDataPortal()
        {
            RuntimeEnvironment.RunLocation = RunLocation.WPF;
            var user = DataPortalClient.Create<UserInfo>();
            var cri = new Criteria();
            cri.AddFilter<UserInfo>(o => o.UserID.Equals("1"));
            user = DataPortalClient.Fetch<UserInfo>(cri);
            DataPortalClient.Fetch<EntityList<UserInfo>>(cri);
            Assert.AreEqual(1, user.UserID);
            //if (user == null)
            //    return;
            //Console.Write(user.UserName);
            user.UserName = "Fuck off 这是中国1";
            //Assert.IsTrue(user.IsDirty);
            user.UserID = 3;
            user.SaveChanges();
            //Assert.IsFalse(user.IsDirty);
            //WooCoo.DataPortal.Update<UserInfo>(user);
            //Assert.IsTrue(user.IsNew);
        }
    }
}
